home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / utils / dos / touch.c < prev   
C/C++ Source or Header  |  1995-04-18  |  982b  |  77 lines

  1.  
  2.  
  3. /*
  4.  *
  5.  *    Copyright 1993 Algorithms Corporation
  6.  *
  7.  *    ALL RIGHTS RESERVED.
  8.  *
  9.  *
  10.  *
  11.  */
  12.  
  13.  
  14.  
  15.  
  16. #include <stdio.h>
  17.  
  18. static    int    touch();
  19.  
  20. main(argc, argv)
  21. int    argc;
  22. char    *argv[];
  23. {
  24.     int    i, err=0;
  25.  
  26.     for (i=1 ; --argc ; ++i)
  27.         err |= touch(argv[i]);
  28.     return err;
  29. }
  30.  
  31. static    int    touch(f)
  32. char    *f;
  33. {
  34.     FILE    *fp;
  35.     int    c, err=0;
  36.  
  37.     if (NULL != (fp = fopen(f,"r+b")))  {
  38.         fseek(fp, 0L, 2);
  39.         if (ftell(fp) == 0L)  {
  40.             fclose(fp);
  41.             unlink(f);
  42.             if (NULL == (fp = fopen(f, "w")))  {
  43.                 fprintf(stderr, "touch:  can't create %s", f);
  44.                 err = 1;
  45.             }
  46.             fclose(fp);
  47.         }  else  {
  48.             fseek(fp, 0L, 0);
  49.             c = fgetc(fp);
  50.             fseek(fp, 0L, 0);
  51.             fputc(c, fp);
  52.             fclose(fp);
  53.         }
  54.     }  else  {
  55.         if (NULL == (fp = fopen(f, "w")))  {
  56.             fprintf(stderr, "touch:  can't create %s", f);
  57.             err = 1;
  58.         }
  59.         fclose(fp);
  60.     }
  61.     return err;
  62. }
  63.  
  64.  
  65.  
  66. /*
  67.  *
  68.  *    Copyright 1993 Algorithms Corporation
  69.  *
  70.  *    ALL RIGHTS RESERVED.
  71.  *
  72.  *
  73.  *
  74.  */
  75.  
  76.  
  77.